#include <QtGui/QMenu>
#include <QtGui/QGraphicsSceneContextMenuEvent>
#include "gpool.h"
#include "APnMScene.h"
#include "link.h"

GPool::~GPool() 
{
	foreach (Link *arrow, mLinks) {
		// arrow will delete itself reference in this object from its destructor
		arrow->scene()->removeItem(arrow);
		delete arrow;
	}
}

void GPool::removeLink(Link *arrow)
{
	int index = mLinks.indexOf(arrow);

	if (index != -1)
		mLinks.removeAt(index);
}

QList<Link*> GPool::allLinks() const
{
	return mLinks;
}

void GPool::addLink(Link *arrow)
{
	mLinks.append(arrow);
}

QVariant GPool::itemChange(GraphicsItemChange change, const QVariant &value)
{
	if (change == QGraphicsItem::ItemPositionChange) {
		foreach (Link *arrow, mLinks) {
			arrow->updatePosition();
		}
	}

	return value;
}